from django.db import models
from User.models import User
from goods.models import *
# Create your models here.
class CartItem(models.Model):
    goodsid = models.IntegerField()
    colorid = models.IntegerField()
    sizeid = models.IntegerField()
    count = models.PositiveIntegerField()    #positive 正的
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    isdelete = models.BooleanField(default=False)

    class Meta:
        unique_together = ['goodsid','colorid','sizeid','user']   #通过四个字段来确定添加到购物车的商品是否重复

    def goods(self):
        return Goods.objects.get(id=self.goodsid)

    def color(self):
        return Color.objects.get(id=self.colorid)

    def size(self):
        return Size.objects.get(id=self.sizeid)

    #返回总价格
    def totalPrice(self):
        return int(self.count) * float(self.goods().price)
